<?php

namespace app\adminapi\export;

use app\services\agent\AgentManageServices;
class AgentSettlementExport extends BaseExport
{
    protected $header = [
        '订单号', '成交金额(元)', '客户昵称', '客户手机号', '分销员昵称', '分销员手机号', '收益类型', '收益(元)','结算状态'
    ];

    public function createData(array $where)
    {
        $list = app()->make(AgentManageServices::class)->agentSettlement($where['time'], $where['agent_phone'], $where['sn'], $where['is_cal'], $where['limit'])['list'];

        $data = [];
        foreach ($list as $item) {
            foreach($item['agent'] as $val){
                $data[] = [
                    $item['sn'],
                    $item['price'],
                    $item['buyer']['nickname'],
                    $item['buyer']['phone'],
                    $val['nickname'],
                    $val['phone'],
                    $val['money_type'],
                    $val['money'],
                    $val['is_cal'] == 1 ? '已结算' : ($val['is_cal'] == 2 ? '待结算' : '已失效')
                ];
            }
        }

        return $data;
    }
}